<template>
   <div>
    
      <div style="margin-bottom: 16px; margin: 0 auto">
        <a-row>
          <a-col :span="24">
            <h1
              style="
                text-align: center;
                color: #337ab7;
                font-size: 25px;
              "
            >
              <span
                class="glyphicon glyphicon-search"
                aria-hidden="true"
              ></span
              ><span style="text-shadow: 0px 0px 4px grey"
                ><a href="javascript:;">{{ entercon }}</a></span
              >
            </h1>
          </a-col>
        </a-row>
         <v-nave></v-nave>
        <a-row type="flex" justify="center">
          
          <a-col 
           :xs="24"
            :sm="24"
            :md="24"
            :lg="22"
            :xl="19">
            <a-input-search
              :placeholder="searchWords == '在这里输入关键词' ?searchWords:'' "
              :value="searchWords == '在这里输入关键词' ?'':searchWords "
              enter-button="检索"
              :allowClear="true"
              @change="SearchChange"
              @search="SearchAction"
            >
            </a-input-search>
          </a-col>
        </a-row>
      </div>
      <div style="margin-top: 16px"></div>
      <!-- 初始化loading加载 -->
    <a-row type="flex" justify="space-around" align="middle" v-show="loading_over && !show_pagination">
      <a-col :span="4">
        <div style="margin-top:40px;margin-bottom:20px">
          <a-spin tip="Loading...">
            <div class="spin-content"></div>
          </a-spin>
        </div>
      </a-col>
    </a-row>
     <!-- 初始化loading加载 end -->
    </div>
</template>
<script>
import VNave from '../../../../components/common/searchnav';
export default {
  data() {
    return {
      // [{ fieldCode: "", fieldValue: "" }]
      searchWords:'在这里输入关键词',
      search_fields_adv: [],
      formLayout: "horizontal",
      form: this.$form.createForm(this, { name: "coordinated" }),
      visible: false,
      entercon: "统一检索",
    };
  },
   components: {
     VNave
  },
  watch: {
  },
  computed: {
    show_pagination() {
      return this.$store.state[this.$store.state.Namedparent.name].books
        .show_pagination;
    },
     loading_over() {
      return this.$store.state[this.$store.state.Namedparent.name].books
        .loading_over;
    },
    //   search
    search_keys() {
      return this.$store.state.Unified.books
        .fieldsAllow.searchKeys;
    },
    search_fields() {
      return this.$store.state.Unified.books
        .fieldsAllow.sortFields;
    },
    getNamedparent() {
      return this.$store.state.Namedparent.key;
    },
  },
  mounted() {
    //  console.log(this.$store.state.Namedparent)
    //   this.$store.state.Namedparent.key == 0 ? (this.entercon ="统一检索") 
    //           : this.$store.state.Namedparent.key == 1 ? (this.entercon ="检索纸书")
    //           : this.$store.state.Namedparent.key == 2 ? (this.entercon ="检索电子书")
    //           : (this.entercon ="检索电子期刊")
    //           console.log(this.$route.query.searchtitle)
              
    //           if(this.$route.query.searchtitle && this.$route.name !='detail'){
    //             this.SearchAction(this.$route.query.searchtitle)
    //           }
    if(this.$route.query.searchtitle){
      this.searchWords = this.$route.query.searchtitle;
    }
  },
  methods: {
    

    SearchChange(e){
        const { value } = e.target;
         this.searchWords = value;
    },
    // 搜索 start
    SearchAction: function (search_keyword) {
      search_keyword= this.searchWords;
      if(search_keyword == '' || search_keyword == "在这里输入关键词"){
        this.$message.error('请输入检索关键字');
        return ;
      }
      this.searchWords = search_keyword;
      this.$store.commit(
        "Unified/UpdateQsSearchKeyWord",
        search_keyword
      );

          this.$store
        .dispatch("Unified/getsiderbar")
        .then(() => {
        setTimeout(()=>{
              this.$store.dispatch(
            "Unified/GetBooks"
          );
        },1000)
        });

      this.$router.push({
        path: "/BookSearch",
        query: { searchtitle: search_keyword },
      });
      this.$store.commit(
        "Unified/Changeloading",
        true
      );
      //

      // this.$store.dispatch(getbooks);
      //console.log(this.$store)

      //   this.$router.push("/");
    },
    // 搜索 end
  },
};
</script>
<style scoped>
/deep/.ant-input{
  height: 43px;
}
/deep/.ant-btn{
  height: 43px;
}
</style>